package net.huashitong.Indicators.service;

import com.sirdc.modules.core.dao.BaseDao;
import com.sirdc.modules.sys.base.StringPKService;
import com.sirdc.modules.sys.service.SysTableService;
import net.huashitong.Indicators.dao.IndexDataDao;
import net.huashitong.Indicators.dataBean.IndexDataDTO;
import net.huashitong.Indicators.entity.IndexData;
import net.huashitong.Indicators.entity.OneIndex;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IndexDataService extends StringPKService<IndexData> {

    @Autowired
    private IndexDataDao dao;


    @Autowired
    private SysTableService tableService;

    @Override
    protected BaseDao<IndexData, String> getDao() {
        return dao;
    }

    @Override
    protected void beforeSave(IndexData obj) {
        obj.setSysId(tableService.updateMaxSysId("AC04", null));
    }

    /**
     * 获取数据库里面最新的日期
     */

    public String getNewCurrentDate(String codeTyep,String areaType) {
        String dateTime = dao.getNewCurrentDate(codeTyep,areaType);
        return dateTime;
    }

    /*
     *获取具体数据
     */
    public IndexData getIndexData(String codeID, String datetime, String areaCode, String codeType, String areaType) {
        return dao.getIndexDataInfo(codeID, datetime, areaCode, codeType, areaType);
    }

    /**
     * @return
     */
    public List<IndexData> getListIndexDate(String codeID, String areaCode, String codeType,String dateTime,String areaType) {

        return dao.getListIndexData(codeID, areaCode, codeType,dateTime,areaType);
    }

    /**
     * 查询数据表里面的数据
     *
     * @param codeID
     * @param datetime
     * @param areaCode
     * @param codeType
     * @return
     */
    public List<IndexDataDTO> queryListIndexDate(String codeID, String datetime, String areaCode, String codeType, String areaType) {
        return dao.queryListData(codeID, datetime, areaCode, codeType, areaType);
    }

    /**
     * 查询数据表里面的数据
     *
     * @param codeID
     * @param datetime
     * @param areaCode
     * @param codeType
     * @return
     */
    public List<IndexDataDTO> queryListIndexDate(String codeID, String datetime, String areaCode, String codeType, String areaType,String codeName) {
        return dao.queryListData(codeID, datetime, areaCode, codeType, areaType,codeName);
    }

    /**
     * 删除数据
     *
     * @param year
     * @param codeType
     */
    public void deleteIndexData(String year, String codeType,String areaType) {
        dao.deleteIndexData(year, codeType, areaType);
    }

    /**
     * 删除数据 带codeId
     *
     * @param year
     * @param codeType
     */
    public void deleteIndexData(String year, String codeType,String areaType,String codeId) {
        dao.deleteIndexData(year, codeType, areaType,codeId);
    }


    /**
     * 删除重复数据
     *
     * @param codeType
     */
    public void deletRepeatData(String codeType, String areatype) {
        dao.deleteRepeatData(codeType, areatype);
    }


    /**
     * 搜索数据
     *
     * @param
     * @return
     */
    public List<IndexDataDTO> getSearchData(String codeID, String datetime, String areaCode, String codeType) {
        return dao.getSearchListData(codeID, datetime, areaCode, codeType);
    }


    /**
     * 获取排名
     *  默认排名增长值
     * @param codeID
     * @param datetime
     * @param areaCode
     * @param codeType
     * @param areaType
     * @return
     */
    public List<IndexDataDTO> getRank(String codeID, String datetime, String areaCode,
                                      String codeType, String areaType, String rankunit,
                                      boolean pingtang) {
        return dao.getRank(codeID, areaCode, datetime, codeType, areaType, rankunit,pingtang);
    }


    /**
     * 各个城市的值
     *
     * @param codeID
     * @param datetime
     * @param areaCode
     * @param codeType
     * @param areaType
     * @return
     */
    public List<IndexDataDTO> getCityValues(String codeID, String datetime, String areaCode, String codeType, String areaType) {
        return dao.getCitysValues(codeID, datetime, codeType, areaType);
    }

    /**
     * 各个城市的值(不含平潭跟福州不含平潭两地区)
     *
     * @param codeID
     * @param datetime
     * @param areaCode
     * @param codeType
     * @param areaType
     * @return
     */
    public List<IndexDataDTO> getCityValuesNoPt(String codeID, String datetime, String areaCode, String codeType, String areaType) {
        return dao.getCitysValuesNoPt(codeID, datetime, codeType, areaType);
    }


    /**
     * @return
     */
    public IndexData getRanks(String dateTime, String codeType, String areaType, String codeId, String areaCode) {
        return dao.getRanks(dateTime, codeType, areaType, codeId, areaCode);
    }




    public  List<IndexData> getNodataCode()
    {
        return dao.getNodataCode();
    }
}
